<?php
namespace app\index\controller;
use think\Debug;
class Request extends \think\Controller{
    use \traits\brximl\brx;
    public function index()
    {
        $this->brxStart();
        $this->useFrontFk();
         $this->loadScript([
            'title'=>'TeCener-数据请求','js'=>['TeC'],'css'=>['TeC','request/index']
        ]);
        $url = isset($_GET['url'])? $_GET['url']:'';
        $this->assign('url',$url);
        if($url) {$this->assign('report',$this->_act_request($url));}
        return $this->fetch('index');
    }
    private function _act_request($url)
    {
        $uParam = parse_url($url);
        Debug::remark('begin');
        $hd = get_headers($url);
        $xhtml = '
            <div class="page-header"><h3>基本信息</h3></div>
            <div class="well">
                <br>请求地址：'.$url.'
                '.(isset($uParam['scheme'])? '<br>协议：'.$uParam['scheme']:'').'
                '.(isset($uParam['host'])? '<br>域名：'.$uParam['host']:'').'
                '.(isset($uParam['path'])? '<br>路劲：'.$uParam['path']:'').'
            </div>
            <div class="page-header"><h3>头部信息</h3></div>
            <div class="well"><ul><li>'.implode('</li><li>',$hd).'</li></div>';
        $tmpXml = '';
        foreach(get_meta_tags($url) as $k=>$v){
            $tmpXml .= '<li>('.$k.') => '.$v.'</li>';
        }   
        if($tmpXml) $xhtml .= '<ul>'.$tmpXml.'</ul>';
        $webScript = '
            <div class="page-header"><h3>脚本内容</h3></div>
            <div class="well">
                <textarea class="show_web_script">'.getStr($url).' </textarea>
            </div>
        ';
        Debug::remark('end');
        $xhtml .= '<p>此时运行时间：'.Debug::getRangeTime('begin','end').'s；内存开销'.Debug::getRangeMem('begin','end').'；时间戳:'.date('Y-m-d H:i:s').'。</p>';
        $xhtml .= $webScript;
        return $xhtml;
    }
}